home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / xgui / sources / ui_action.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  65.5 KB  |  2,077 lines

  1. /*****************************************************************************
  2.   FILE           : ui_action.c
  3.   SHORTNAME      : action.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        :
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Tilman Sommer
  10.   DATE           : 6.6.1990
  11.  
  12.   CHANGED BY     : Niels Mache
  13.   IDENTIFICATION : @(#)ui_action.c    1.19 3/23/94
  14.   SCCS VERSION   : 1.19
  15.   LAST CHANGE    : 3/23/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.              
  19. ******************************************************************************/
  20.  
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <malloc.h>
  25.  
  26. #include "ui.h"
  27. #include "ui_selection.h"
  28.  
  29. #include "kr_ui.h"
  30.  
  31. #include <X11/Xaw/List.h>
  32.  
  33. #include "ui_utilP.h"
  34. #include "ui_netUpdate.h"
  35. #include "ui_confirmer.h"
  36. #include "ui_xWidgets.h"
  37. #include "ui_display.h"
  38. #include "ui_remoteP.h"
  39. #include "ui_xGraphic.h"   /* ui_xDrawPoint */
  40. #include "ui_mainP.h"
  41. #include "ui_lists.h"
  42. #include "ui_infoP.h"
  43. #include "ui_textP.h"
  44. #include "ui_netGraph.h"
  45. #include "d3_global.h"
  46. #include "d3_lists.h"
  47. #include "d3_main.h"
  48. #include "ui_key.h"
  49. #include "ui_info.h"
  50. #include "ui_layer.h"
  51.  
  52. #include "ui_action.ph"
  53.          
  54.  
  55. /*****************************************************************************
  56.   FUNCTION : ui_action_init
  57.  
  58.   PURPOSE  :
  59.   RETURNS  : void
  60.   NOTES    :
  61.  
  62.   UPDATE   : 20.9.1990
  63. ******************************************************************************/
  64.  
  65. void ui_action_init (void)
  66.  
  67. {
  68.     sprintf(ui_action_listSite.msg,"Select Site");
  69.     ui_action_listSite.widgetPtr      = NULL;
  70.     ui_action_listSite.listWidget     = NULL;
  71.     ui_action_listSite.listPtr        = NULL;
  72.     ui_action_listSite.noOfAllocItems = 0;
  73.     ui_action_listSite.noOfItems      = 0;
  74.     ui_action_listSite.unitPtr        = NULL;
  75.     ui_action_listSite.listType       = UI_LIST_SITE;                
  76. }
  77.  
  78.  
  79. /*****************************************************************************
  80.   FUNCTION : ui_action_isNewUnit
  81.  
  82.   PURPOSE  : called from ui_action_unitsCopy to determine, whether the unit
  83.              unitNo was just created by the copy command
  84.   RETURNS  : Bool
  85.   NOTES    : 
  86.  
  87.   UPDATE   : 20.9.1990
  88. ******************************************************************************/
  89.  
  90. static Bool ui_action_isNewUnit (int unitNo)
  91.  
  92. {
  93.     struct SelectionType     *selPtr;
  94.         
  95.     for (selPtr = ui_sel_listPtr;
  96.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  97.      selPtr = selPtr->nextPtr) {
  98.         
  99.     /* check whether there is already a unit at destination */
  100.     if (selPtr->copyNo == unitNo) return(TRUE);
  101.     }
  102.     return(FALSE);
  103. }
  104.  
  105.  
  106. /*****************************************************************************
  107.   FUNCTION : ui_action_createLink
  108.  
  109.   PURPOSE  : creates a link 
  110.   RETURNS  : Bool
  111.   NOTES    : returns TRUE, if operation was successful
  112.              The current unit/site/link pointers will always be restored
  113.          after the operation was done.
  114.          siteName may be "" indicating a direct link 
  115.  
  116.   UPDATE   : 20.9.1990
  117. ******************************************************************************/
  118.  
  119. static Bool ui_action_createLink (int source, int target, char siteName[], 
  120.         FlintType weight)
  121.  
  122. {
  123.     int       curUnit = krui_getCurrentUnit();
  124.     char      curSiteName[MAX_NAME_LENGTH];
  125.     FlintType w;
  126.     int       curPredUnit = 0;
  127.     int       isRecLink ;
  128.  
  129.     if (krui_getUnitInputType(curUnit) == SITES) 
  130.     strcpy(curSiteName, krui_getSiteName());
  131.     else
  132.     curSiteName[0] = '\0';
  133.     
  134.     if (krui_setCurrentUnit(target) != UI_SET_OK) {
  135.     if (curUnit > 0) krui_setCurrentUnit(curUnit); /* restore */
  136.     return(FALSE); /* target doesn't exist */
  137.     }
  138.  
  139.     if (((krui_getUnitInputType(target) == SITES) AND NOT strlen(siteName)) OR
  140.     ((krui_getUnitInputType(target) != SITES) AND strlen(siteName))) {
  141.     if (curUnit > 0) krui_setCurrentUnit(curUnit); /* restore */
  142.     return(FALSE); /* creation impossible */
  143.     }
  144.     
  145.     if (strlen(siteName) AND (krui_setSite(siteName) != UI_SET_OK)) {
  146.     if (curUnit > 0) {
  147.         krui_setCurrentUnit(curUnit); /* restore */
  148.         if (krui_getUnitInputType(target) == SITES) {
  149.         (void) krui_setSite(curSiteName);
  150.         if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  151.         }
  152.     }        
  153.     return(FALSE); /* this site doesn't exist on target */
  154.     }
  155.  
  156.     if (krui_isConnected(source)) {
  157.     if (curUnit > 0) {
  158.         krui_setCurrentUnit(curUnit); /* restore */
  159.         if (krui_getUnitInputType(target) == SITES) {
  160.         (void) krui_setSite(curSiteName);
  161.         if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  162.         }
  163.     }        
  164.     return(FALSE); /* link already exist */
  165.     }
  166.  
  167.     isRecLink = ui_areConnected (target, source) ;
  168.  
  169.     if (isRecLink){
  170.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, target, source,
  171.             krui_getLinkWeight(), UI_ERASE);
  172.     }                        
  173.  
  174.     ui_checkError(krui_createLink(source, weight));
  175.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, source, target, weight, UI_DRAW);
  176.  
  177.     if (isRecLink){
  178.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, target, source,
  179.             krui_getLinkWeight(), UI_DRAW);
  180.     }
  181.  
  182.     if (curUnit > 0) {
  183.     krui_setCurrentUnit(curUnit); /* restore */
  184.     if (krui_getUnitInputType(target) == SITES) 
  185.         (void) krui_setSite(curSiteName);
  186.     if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  187.     }        
  188.     
  189.     return(TRUE);  /* success */
  190.  
  191. }
  192.  
  193.  
  194. /*****************************************************************************
  195.   FUNCTION : ui_action_deleteLink
  196.  
  197.   PURPOSE  :
  198.   RETURNS  : Bool
  199.   NOTES    : returns TRUE, if operation was successful
  200.              see ui_action_createLink
  201.  
  202.   UPDATE   : 20.9.1990
  203. ******************************************************************************/
  204.  
  205. static Bool ui_action_deleteLink (int source, int target, char siteName[])
  206.  
  207. {
  208.     int       curUnit = krui_getCurrentUnit();
  209.     char      curSiteName[MAX_NAME_LENGTH];
  210.     FlintType w;
  211.     int       curPredUnit = krui_getCurrentPredUnit(&w);
  212.     int       isRecLink = 0 ;
  213.  
  214.     if (krui_getUnitInputType(curUnit) == SITES) 
  215.     strcpy(curSiteName, krui_getSiteName());
  216.     else
  217.     curSiteName[0] = '\0';
  218.  
  219.     if (krui_setCurrentUnit(target) != UI_SET_OK) {
  220.     if (curUnit > 0) krui_setCurrentUnit(curUnit); /* restore */
  221.     return(FALSE); /* target doesn't exist */
  222.     }
  223.  
  224.     if (((krui_getUnitInputType(target) == SITES) AND NOT strlen(siteName)) OR
  225.     ((krui_getUnitInputType(target) != SITES) AND strlen(siteName))) {
  226.     if (curUnit > 0) krui_setCurrentUnit(curUnit); /* restore */
  227.     return(FALSE); /* creation impossible */
  228.     }
  229.     
  230.     if (strlen(siteName) AND (krui_setSite(siteName) != UI_SET_OK)) {
  231.     if (curUnit > 0) {
  232.         krui_setCurrentUnit(curUnit); /* restore */
  233.         if (krui_getUnitInputType(target) == SITES) {
  234.         (void) krui_setSite(curSiteName);
  235.         if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  236.         }
  237.     }        
  238.     return(FALSE); /* this site doesn't exist on target */
  239.     }
  240.  
  241.     if (NOT krui_isConnected(source)) {
  242.     if (curUnit > 0) {
  243.         krui_setCurrentUnit(curUnit); /* restore */
  244.         if (krui_getUnitInputType(target) == SITES) {
  245.         (void) krui_setSite(curSiteName);
  246.         if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  247.         }
  248.     }        
  249.     return(FALSE); /* link doesn't  exist */
  250.     }
  251.  
  252.     isRecLink = ui_areConnected (target, source) ;
  253.  
  254.     if (isRecLink){
  255.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, target, source,
  256.             krui_getLinkWeight(), UI_ERASE);
  257.  
  258.     }
  259.  
  260.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, source, target, 
  261.             krui_getLinkWeight(), UI_ERASE);
  262.     krui_deleteLink();
  263.  
  264.     if (isRecLink){
  265.     ui_net_drawLink(ui_currentDisplay, UI_GLOBAL, target, source,
  266.             krui_getLinkWeight(), UI_DRAW);
  267.  
  268.     }
  269.  
  270.     if (curUnit > 0) {
  271.     krui_setCurrentUnit(curUnit); /* restore */
  272.     if (krui_getUnitInputType(target) == SITES) 
  273.         (void) krui_setSite(curSiteName);
  274.     if (curPredUnit > 0) (void) krui_isConnected(curPredUnit);
  275.     }
  276.     return(TRUE);
  277. }
  278.  
  279.  
  280. /*****************************************************************************
  281.   FUNCTION : ui_action_getSite
  282.  
  283.   PURPOSE  : cause the user to select a site if there are any. If unitNo
  284.              is 0 ( = UI_GENERAL) the selection list contains all site 
  285.          names found. Else all sites off the given unit will be listed.
  286.   RETURNS  : Bool
  287.   NOTES    :
  288.  
  289.   UPDATE   : 20.9.1990
  290. ******************************************************************************/
  291.  
  292. static Bool  ui_action_getSite (int unitNo)
  293.  
  294. {
  295.     char        *name, *funcName;
  296.     Position    x, y;
  297.  
  298.     ui_action_siteName[0] = '\0';
  299.  
  300.     if ((unitNo != UI_GENERAL) AND (krui_getUnitInputType(unitNo) != SITES))
  301.     /* specified unit has no sites! */
  302.     return(FALSE); /* direct links */
  303.     
  304.     if ((unitNo == UI_GENERAL) AND 
  305.     NOT krui_getFirstSiteTableEntry(&name, &funcName))
  306.     /* no sites defined */
  307.     return(FALSE);
  308.  
  309.     if (unitNo != UI_GENERAL) {
  310.     (void) krui_setCurrentUnit(unitNo);
  311.     ui_action_listSite.listType       = UI_LIST_UNIT_SITE; 
  312.     } else
  313.     ui_action_listSite.listType       = UI_LIST_SITE;                
  314.                
  315.     /* display site popup */
  316.     XtTranslateCoords(ui_currentDisplay->widget, 
  317.               (Position) 10, (Position) 10, &x, &y);
  318.     ui_listPopup(&ui_action_listSite, x, y);
  319.     if (ui_list_returnIndex < 0) 
  320.     return(FALSE); /* direct links */
  321.     else {
  322.     strcpy(ui_action_siteName, ui_list_returnName);
  323.     return(TRUE);  /* site choosed */
  324.     }
  325. }
  326.  
  327.  
  328. /*****************************************************************************
  329.   FUNCTION : ui_action_checkNewPositions
  330.  
  331.   PURPOSE  : This routine is called by actions MOVE and COPY in order to 
  332.              determine first whether to perform the operation or not.
  333.   RETURNS  : TRUE, if the operation can be performed, else FALSE.
  334.   NOTES    : kindOfAction:  UI_ACTION_MOVE or UI_ACTION_COPY
  335.  
  336.   UPDATE   : 1.2.1990
  337. *****************************************************************************/
  338.  
  339. static Bool ui_action_checkNewPositions (int kindOfAction)
  340.  
  341. {
  342.     struct PosType           moveToPosition;
  343.     struct SelectionType     *selPtr;
  344.     int               deltaX = ui_key_eventPos.x - ui_targetUnit.gridPos.x;
  345.     int               deltaY = ui_key_eventPos.y - ui_targetUnit.gridPos.y;
  346.     int               unitNoAtDest;
  347.     
  348.     selPtr = ui_sel_listPtr;
  349.  
  350.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  351.     
  352.     moveToPosition.x = selPtr->gridPos.x + deltaX;
  353.     moveToPosition.y = selPtr->gridPos.y + deltaY;
  354.     moveToPosition.z = selPtr->gridPos.z;
  355.     
  356.     /* check whether there is already a unit at destination */
  357.     if ((unitNoAtDest = 
  358.          krui_getUnitNoAtPosition(&moveToPosition, ui_currentDisplay->subNetNo)) > 0)
  359.         if ((kindOfAction != UI_ACTION_MOVE) OR
  360.         (ui_sel_lookForItem(unitNoAtDest) == NULL)) 
  361.         /* if UI_ACTION_COPY or 
  362.            UI_ACTION_MOVE and unitNoAtDest isn't selected */
  363.         return(FALSE); 
  364.     selPtr = selPtr->nextPtr;
  365.     }
  366.     return(TRUE);
  367. }
  368.  
  369.  
  370. /*****************************************************************************
  371.   FUNCTION : ui_actions_unitsMove
  372.  
  373.   PURPOSE  : move all selected units. The destination position is determined
  374.              by the position of the target-unit (unit-info-panel) and the
  375.          position in ui_key_eventPos.
  376.   RETURNS  : void
  377.   NOTES    : First the dest positions are checked.
  378.              Then the first unit to move is considered (depends of the 
  379.          direction of the move).
  380.          The move is performed.
  381.          Finally, draw the whole net.
  382.  
  383.   UPDATE   :
  384. *****************************************************************************/
  385.  
  386. void ui_action_unitsMove (void)
  387.  
  388. {
  389.     struct PosType       moveToPosition; /* target position */
  390.     struct SelectionType *maxUnitSelPtr;       /* ptr to the first unit to move */
  391.     struct SelectionType *selPtr, *mainSelPtr;         
  392.     int                  deltaX = ui_key_eventPos.x - ui_targetUnit.gridPos.x;
  393.     int                  deltaY = ui_key_eventPos.y - ui_targetUnit.gridPos.y;
  394.     int                  maxUnitSelPtrDeltaX;
  395.     int                  maxUnitSelPtrDeltaY;
  396.  
  397.     if (ui_action_checkNewPositions(UI_ACTION_MOVE)) {
  398.  
  399.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  400.  
  401.     mainSelPtr = ui_sel_listPtr;
  402.     while ((mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL) {
  403.  
  404.         maxUnitSelPtr = NULL;  /* signal, that no such unit was found yet */
  405.  
  406.         if (ui_utilIsSet(mainSelPtr->flags, UI_ALREADY_MOVED)) 
  407.         mainSelPtr = mainSelPtr->nextPtr;
  408.         else {
  409.         /* look for the first unit to move (-> maxUnitSelPtr!)*/
  410.         maxUnitSelPtr = mainSelPtr; /* Consider this one to move first. */
  411.         selPtr  = mainSelPtr; /* start here, because mainSelPtr holds
  412.                      always the first unit not moved. */
  413.  
  414.         while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  415.             
  416.             if (ui_utilIsNotSet(selPtr->flags, UI_ALREADY_MOVED)) {
  417.             /* The current unit was not moved already. */
  418.             maxUnitSelPtrDeltaX = 
  419.                 selPtr->gridPos.x - maxUnitSelPtr->gridPos.x;
  420.             maxUnitSelPtrDeltaY = 
  421.                 selPtr->gridPos.y - maxUnitSelPtr->gridPos.y;
  422.             
  423.             if ((deltaX * maxUnitSelPtrDeltaX >= 0) AND
  424.                 (deltaY * maxUnitSelPtrDeltaY >= 0))
  425.                 /* Both values have the same sign => the current 
  426.                    unit has to be treated first ! */
  427.                 maxUnitSelPtr     = selPtr;
  428.             }
  429.             selPtr = selPtr->nextPtr;
  430.         }
  431.         /* The unit to move was found now. */
  432.         /* move the unit referred by maxUnitSelPtr */
  433.         moveToPosition.x = maxUnitSelPtr->gridPos.x + deltaX;
  434.         moveToPosition.y = maxUnitSelPtr->gridPos.y + deltaY;
  435.         moveToPosition.z = maxUnitSelPtr->gridPos.z;
  436.     
  437.         /* if the current target unit in the info panel is selected,
  438.            then update its position too. */
  439.         if (maxUnitSelPtr->unitNo == ui_targetUnit.no)
  440.             ui_targetUnit.gridPos = moveToPosition;
  441.  
  442.         /* erase unit and links at old position first */
  443.         ui_net_drawAllLinksToUnit(ui_currentDisplay, UI_GLOBAL, 
  444.                       maxUnitSelPtr->unitNo, UI_ERASE);
  445.         ui_net_drawAllLinksFromUnit(ui_currentDisplay, UI_GLOBAL, 
  446.                         maxUnitSelPtr->unitNo, UI_ERASE);
  447.         ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  448.                 maxUnitSelPtr->unitNo, UI_ERASE);
  449.     
  450.         /* call kernal */
  451.         krui_setUnitPosition(maxUnitSelPtr->unitNo, &moveToPosition);
  452.          krui_setUnitSubnetNo(maxUnitSelPtr->unitNo, 
  453.                      ui_currentDisplay->subNetNo);
  454.         /* alter position in selection list */
  455.         maxUnitSelPtr->gridPos = moveToPosition;  
  456.         /* draw unit and links at new position */
  457.         ui_net_drawAllLinksToUnit(ui_currentDisplay, UI_GLOBAL, 
  458.                       maxUnitSelPtr->unitNo, UI_DRAW);
  459.         ui_net_drawAllLinksFromUnit(ui_currentDisplay, UI_GLOBAL, 
  460.                         maxUnitSelPtr->unitNo, UI_DRAW);
  461.         ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  462.                 maxUnitSelPtr->unitNo, UI_DRAW);
  463.         /* mark unit as moved */
  464.         ui_utilSetFlag(maxUnitSelPtr->flags, UI_ALREADY_MOVED);
  465.         /* start from beginning of the selection list again */
  466.         mainSelPtr = ui_sel_listPtr;
  467.     }
  468.         /* In both cases of this if-statement, mainSelPtr helds a 
  469.            new pointer to continue the move-ooperation. */
  470.     }
  471.     
  472.     /* the move operation is done */
  473.     /* reset all Flags UI_ALREADY_MOVED */
  474.     selPtr = ui_sel_listPtr;
  475.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  476.         ui_utilResetFlag(selPtr->flags, UI_ALREADY_MOVED);
  477.         selPtr = selPtr->nextPtr;
  478.     }
  479.         d3_drawNet ();
  480.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  481.     } else 
  482.     ui_confirmOk("Can't move units to this position!");
  483. }
  484.  
  485.  
  486. /*****************************************************************************
  487.   FUNCTION : ui_action_unitsCopy
  488.  
  489.   PURPOSE  : copy all selected units in the current mode to another position.
  490.   RETURNS  : alteration of the network
  491.   NOTES    : The operation is very similar to ui_action_unitsMove(). The copy
  492.              operation takes attention on the flag-word ui_linksToHandle.
  493.          A special case is the copying of the topological structure, which
  494.          is handled on the end of the routine separately from the actual
  495.          copying of the units itsself.
  496.  
  497.   UPDATE   :
  498. *****************************************************************************/
  499.  
  500. void ui_action_unitsCopy(void)
  501.  
  502. {
  503.     struct PosType  moveToPosition;         /* position while copying */
  504.  
  505.     FlintType weight;  /* used while structureCopy */
  506.     FlintType infoWeight;
  507.  
  508.      /* Ptrs to step through the selection list */
  509.  
  510.     struct SelectionType     *mainSelPtr, *selPtr;
  511.     int               deltaX = ui_key_eventPos.x - ui_targetUnit.gridPos.x;
  512.     int               deltaY = ui_key_eventPos.y - ui_targetUnit.gridPos.y;
  513.  
  514.     Bool              structureCopy;
  515.     int               copyMode;
  516.     int               predUnit;        
  517.  
  518.  
  519.     /* *******************  start ********************************* */
  520.  
  521.     if (NOT ui_action_checkNewPositions(UI_ACTION_COPY)) {
  522.     ui_confirmOk("Can't move units to this position!");
  523.     return;
  524.     }
  525.  
  526.     /* check wether to copy the structure and keep it in mind */
  527.     structureCopy = ui_utilIsSet(ui_key_linksToHandle, UI_STRUCTURE_COPY);
  528.  
  529.     /* reset in either case the flag UI_STRUCTURE_COPY */
  530.     ui_utilResetFlag(ui_key_linksToHandle, UI_STRUCTURE_COPY);
  531.  
  532.     /* now transform ui_key_linksTpHandle to kernal values */
  533.     switch (ui_key_linksToHandle BIT_AND UI_ALL) {
  534.       case UI_ALL    : copyMode = ONLY_OUTPUTS ; break; /* input links will be  
  535.                                treated later */
  536.       case UI_NO_FLAG: copyMode = ONLY_UNIT    ; break;
  537.       case UI_OUT    : copyMode = ONLY_OUTPUTS ; break;
  538.       case UI_INPUT  : copyMode = ONLY_INPUTS  ; break;
  539.     }
  540.  
  541.     if (structureCopy AND (ui_utilIsSet(ui_key_linksToHandle, UI_BACKWARD_BINDING) OR
  542.                ui_utilIsSet(ui_key_linksToHandle, UI_FORWARD_BINDING)))
  543.     (void) ui_action_getSite(UI_GENERAL);
  544.     else
  545.     ui_action_siteName[0] = '\0';
  546.     
  547.     infoWeight = (FlintType) ui_xFloatFromAsciiWidget(ui_linkWidgets.weight);
  548.  
  549.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* hide markers */
  550.  
  551.     for (selPtr = ui_sel_listPtr; 
  552.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  553.      selPtr = selPtr->nextPtr) {
  554.     moveToPosition.x = selPtr->gridPos.x + deltaX;
  555.     moveToPosition.y = selPtr->gridPos.y + deltaY;
  556.     moveToPosition.z = selPtr->gridPos.z;
  557.     /* call kernal */
  558.     selPtr->copyNo   = krui_copyUnit(selPtr->unitNo, copyMode);
  559.     /* Sites are copied as well in either case. */
  560.     krui_setUnitPosition(selPtr->copyNo, &moveToPosition);
  561.     krui_setUnitSubnetNo(selPtr->copyNo, ui_currentDisplay->subNetNo);
  562.  
  563.     /* draw unit and current links at new position */
  564.     ui_net_drawAllLinksToUnit(ui_currentDisplay, UI_GLOBAL, 
  565.                   selPtr->copyNo, UI_DRAW);
  566.     ui_net_drawAllLinksFromUnit(ui_currentDisplay, UI_GLOBAL, 
  567.                     selPtr->copyNo, UI_DRAW);
  568.     ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  569.             selPtr->copyNo, UI_DRAW);
  570.  
  571.     if (structureCopy) {
  572.         /* make bindings to the origin units if required */
  573.         
  574.         if (ui_utilIsSet(ui_key_linksToHandle, UI_FORWARD_BINDING))
  575.         /* original unit is source ! */
  576.         ui_action_createLink(selPtr->unitNo, selPtr->copyNo,
  577.                      ui_action_siteName, infoWeight);
  578.         
  579.         if (ui_utilIsSet(ui_key_linksToHandle, UI_BACKWARD_BINDING)) 
  580.         /* original unit is target */
  581.         ui_action_createLink(selPtr->copyNo, selPtr->unitNo,
  582.                      ui_action_siteName, infoWeight);
  583.     }        
  584.     }
  585.  
  586.     /* if COPY ALL: output links are copied by the kernel. Now copy input links */
  587.     
  588.     if (ui_utilIsSet(ui_key_linksToHandle, UI_ALL)) {
  589.     for (mainSelPtr = ui_sel_listPtr;
  590.          /* outer loop to step through all selected units */
  591.          (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  592.          mainSelPtr = mainSelPtr->nextPtr) {
  593.         
  594.         if (krui_getUnitInputType(mainSelPtr->unitNo) == SITES) {
  595.         bool  successful;
  596.         /* unit with sites: for all sites copy incoming links */
  597.         (void) krui_setCurrentUnit(mainSelPtr->unitNo); /* target */
  598.         for (successful = krui_setFirstSite();
  599.              successful; successful = krui_setNextSite()) {
  600.             for(predUnit = krui_getFirstPredUnit(&weight);
  601.             predUnit > 0;
  602.             predUnit = krui_getNextPredUnit(&weight)) {
  603.             if (ui_action_isNewUnit(predUnit)) continue;
  604.             /* there is a link from an old unit to this site */
  605.             ui_action_createLink(predUnit, mainSelPtr->copyNo, 
  606.                          krui_getSiteName(), weight);
  607.             }
  608.         }
  609.         } else { /* direct links */
  610.         (void) krui_setCurrentUnit(mainSelPtr->unitNo); /* target */
  611.         for(predUnit = krui_getFirstPredUnit(&weight);
  612.             predUnit > 0;
  613.             predUnit = krui_getNextPredUnit(&weight)) {        
  614.             if (ui_action_isNewUnit(predUnit)) continue;
  615.             /* there is a link from an old unit */
  616.             ui_action_createLink(predUnit, mainSelPtr->copyNo, "", weight);
  617.         }
  618.         }
  619.     }
  620.     } /* endif UI_ALL */
  621.  
  622.     /* if structureCopy then copy the link structure of the source */
  623.     
  624.     if (structureCopy) { 
  625.  
  626.     for (mainSelPtr = ui_sel_listPtr;
  627.          /* outer loop to step through all selected units */
  628.          (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  629.          mainSelPtr = mainSelPtr->nextPtr) {
  630.  
  631.         for (selPtr = mainSelPtr;
  632.          /* inner loop */
  633.          (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  634.          selPtr = selPtr->nextPtr) {
  635.  
  636.         /* check the first direction (mainSel -> sel) */
  637.         if (krui_getUnitInputType(selPtr->unitNo) == SITES) {
  638.             /* unit with sites: for all sites copy links */
  639.             bool  successful;
  640.             (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  641.             for (successful = krui_setFirstSite();
  642.              successful; successful = krui_setNextSite()) 
  643.             if (krui_isConnected(mainSelPtr->unitNo)) 
  644.                 /* there is a link to this site */
  645.                 ui_action_createLink(mainSelPtr->copyNo, selPtr->copyNo,
  646.                          krui_getSiteName(), krui_getLinkWeight());
  647.             
  648.         } else { /* unit with direct links */
  649.             (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  650.             if (krui_isConnected(mainSelPtr->unitNo)) 
  651.             ui_action_createLink(mainSelPtr->copyNo, selPtr->copyNo, 
  652.                          "", krui_getLinkWeight());
  653.         }
  654.         
  655.         /* check the other direction (sel -> mainSel) */
  656.         if (krui_getUnitInputType(mainSelPtr->unitNo) == SITES) {
  657.             /* unit with sites: for all sites copy links */
  658.             bool  successful;
  659.             (void) krui_setCurrentUnit(mainSelPtr->unitNo); /* target */
  660.             for (successful = krui_setFirstSite();
  661.              successful; successful = krui_setNextSite()) 
  662.             if (krui_isConnected(selPtr->unitNo)) 
  663.                 /* there is a link to this site */
  664.                 ui_action_createLink(selPtr->copyNo, mainSelPtr->copyNo,
  665.                          krui_getSiteName(), krui_getLinkWeight());
  666.             
  667.         } else { /* unit with direct links */
  668.             (void) krui_setCurrentUnit(mainSelPtr->unitNo); /* target */
  669.             if (krui_isConnected(selPtr->unitNo)) 
  670.             ui_action_createLink(selPtr->copyNo, mainSelPtr->copyNo,
  671.                          "", krui_getLinkWeight());
  672.         }
  673.         }
  674.     }
  675.     } /* endif "structureCopy" */
  676.     d3_drawNet ();
  677.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show markers */
  678. }
  679.  
  680.  
  681. /*****************************************************************************
  682.   FUNCTION : ui_action_linksMakeFromSourceUnit
  683.  
  684.   PURPOSE  : Insert links from the unit under the raster cursor to all 
  685.              selected units.
  686.   RETURNS  : alteration of the network
  687.   NOTES    :
  688.  
  689.   UPDATE   :
  690. *****************************************************************************/
  691.  
  692. void ui_action_linksMakeFromSourceUnit (int op)
  693.  
  694. {
  695.     int                   sourceNo;
  696.     FlintType             weight;
  697.     struct SelectionType  *selPtr;
  698.  
  699.     (void) ui_action_getSite(UI_GENERAL);
  700.  
  701.     if ((sourceNo = ui_key_unitNo) <= 0) return;
  702.     
  703.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* erase the selection markers */
  704.     
  705.     weight = (FlintType) ui_xFloatFromAsciiWidget(ui_linkWidgets.weight);
  706.     
  707.     for (selPtr = ui_sel_listPtr;
  708.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  709.      selPtr = selPtr->nextPtr) 
  710.     if (op == UI_DRAW)
  711.         ui_action_createLink(sourceNo, selPtr->unitNo, 
  712.                  ui_action_siteName, weight);
  713.     else
  714.         ui_action_deleteLink(sourceNo, selPtr->unitNo, 
  715.                  ui_action_siteName);
  716.  
  717.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);  
  718.     /* draw selection markers again */
  719.     ui_info_makeUnitInfoPanelConsistent(); 
  720. }
  721.  
  722.  
  723. /*****************************************************************************
  724.   FUNCTION : ui_action_linksMakeToTargetUnit
  725.  
  726.   PURPOSE  : Insert links from all selected units to the unit under the
  727.              raster-cursor.
  728.   RETURNS  : alteration of the network
  729.   NOTES    :
  730.  
  731.   UPDATE   :
  732. *****************************************************************************/
  733.  
  734. void ui_action_linksMakeToTargetUnit (int op)
  735.  
  736. {
  737.     int                   targetNo;
  738.     struct SelectionType  *selPtr;
  739.     FlintType             weight;
  740.  
  741.     if ((targetNo = ui_key_unitNo) <= 0) return;
  742.  
  743.     (void) ui_action_getSite(targetNo);
  744.     
  745.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  746.     
  747.     weight = (FlintType) ui_xFloatFromAsciiWidget(ui_linkWidgets.weight);
  748.     
  749.     for (selPtr = ui_sel_listPtr;
  750.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  751.      selPtr = selPtr->nextPtr) 
  752.     if (op == UI_DRAW)
  753.         ui_action_createLink(selPtr->unitNo, targetNo, 
  754.                  ui_action_siteName, weight);
  755.     else
  756.         ui_action_deleteLink(selPtr->unitNo, targetNo, 
  757.                  ui_action_siteName);
  758.  
  759.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); 
  760.     ui_info_makeUnitInfoPanelConsistent(); 
  761. }
  762.  
  763.  
  764. /*****************************************************************************
  765.   FUNCTION : ui_action_unitInsert
  766.  
  767.   PURPOSE  : Insert one unit with the attributes of the displayed source-unit
  768.              in the unit-info-panel.
  769.   RETURNS  : alteration of the network
  770.   NOTES    : This routine got not the name 'ui_action_unitsInsert()', because
  771.              it always handles with only one unit!
  772.          The markers normally need not to be deleted, but if the new unit
  773.          overlaps a marker, a ugly spot will occur. So do it!
  774.  
  775.   UPDATE   :
  776. *****************************************************************************/
  777.  
  778. void ui_action_unitInsert (int insertType)
  779.  
  780. {
  781.     Position                   x, y; /* for f-type list panel */
  782.     static struct SimpleListType  listFType;
  783.     struct UnitAttributeType  unit;
  784.     int                       newUnitNo;
  785.  
  786.     if ((newUnitNo = ui_key_unitNo) <= 0) {
  787.     /* this position is free */
  788.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  789.     switch (insertType) {
  790.       case UI_INSERT_DEFAULT:
  791.         newUnitNo = krui_createDefaultUnit();
  792.         break;
  793.       case UI_INSERT_TARGET:
  794.         newUnitNo = krui_createDefaultUnit();
  795.         if (newUnitNo > 0) {
  796.         unit = ui_targetUnit;
  797.         ui_info_getDisplayedUnitAttributes(&ui_targetWidgets, &unit); 
  798.         ui_info_storeAttributes(newUnitNo, unit);
  799.         }
  800.         break;
  801.       case UI_INSERT_FTYPE:
  802.         ui_info_initUnitStruct(&unit);
  803.         XtTranslateCoords(ui_currentDisplay->widget, 
  804.                   (Position) 5, (Position) 5, &x, &y);    
  805.         sprintf(listFType.msg,"Insert f-type unit");
  806.         listFType.unitPtr  = &unit;
  807.         listFType.widgetPtr= NULL;
  808.         listFType.listType = UI_LIST_FTYPE;
  809.         ui_listPopup((struct SimpleListType *) &listFType, x,y);
  810.         newUnitNo = krui_createFTypeUnit(unit.ftype);
  811.         /* if no f-type was selected, unit.ftype holds "?".
  812.            The kernel will not insert unit, because this is an invalid
  813.            f-type and newUnitNo will be -20 (Error 20) */
  814.         break;
  815.     }
  816.  
  817.     if (newUnitNo > 0) {
  818.         krui_setUnitSubnetNo(newUnitNo, ui_currentDisplay->subNetNo);
  819.             ui_key_eventPos.z = ui_actualZvalue;
  820.         krui_setUnitPosition(newUnitNo, &ui_key_eventPos);
  821.         krui_setUnitLayerNo(newUnitNo, (int) ui_currentDisplay->layers);
  822.         ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  823.                 newUnitNo, UI_DRAW);
  824.     }
  825.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* draw markers */
  826.         d3_drawNet ();
  827.     }
  828. }
  829.  
  830.  
  831. /*****************************************************************************
  832.   FUNCTION : ui_action_linksMakeBidirectional
  833.  
  834.   PURPOSE  : Insert links beetween all selected units, that all existing
  835.              single links become bidirectional links.
  836.   RETURNS  : alteration of the network
  837.   NOTES    :
  838.  
  839.   UPDATE   :
  840. *****************************************************************************/
  841.  
  842. void ui_action_linksMakeBidirectional (void)
  843.  
  844. {
  845.     struct SelectionType  *selPtr, *mainSelPtr;
  846.     bool                  successful;
  847.  
  848.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  849.  
  850.     for (mainSelPtr = ui_sel_listPtr;
  851.      (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  852.      mainSelPtr = mainSelPtr->nextPtr) { 
  853.     /* main loop */
  854.  
  855.     for (selPtr = ui_sel_listPtr;
  856.          (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  857.          selPtr = selPtr->nextPtr) { 
  858.         /* inner loop */
  859.  
  860.         if (selPtr == mainSelPtr) continue;
  861.  
  862.         if (krui_getUnitInputType(selPtr->unitNo) == SITES) {
  863.         (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  864.         for (successful = krui_setFirstSite(); successful;
  865.              successful = krui_setNextSite()) {
  866.             if (krui_isConnected(mainSelPtr->unitNo)) 
  867.             ui_action_createLink(selPtr->unitNo, mainSelPtr->unitNo,
  868.                          krui_getSiteName(), krui_getLinkWeight());
  869.         }
  870.         } else {
  871.         /* direct links */
  872.         (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  873.         if (krui_isConnected(mainSelPtr->unitNo)) 
  874.             ui_action_createLink(selPtr->unitNo, mainSelPtr->unitNo,
  875.                      "", krui_getLinkWeight());
  876.         }
  877.     }
  878.     }
  879.     ui_info_makeUnitInfoPanelConsistent(); 
  880.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show markers */
  881. }
  882.  
  883.  
  884. /*****************************************************************************
  885.   FUNCTION : ui_action_linksMakeReverse
  886.  
  887.   PURPOSE  : Alter the Direction of the links beetween all selected units.
  888.   RETURNS  : alteration of the network
  889.   NOTES    : For all units: 
  890.                reverse incoming links from not marked, but selected units
  891.            reverse outgoing links to selected units
  892.            mark unit (this means: all incoming links are reversed links)
  893.  
  894.   UPDATE   :
  895. *****************************************************************************/
  896.  
  897. void ui_action_linksMakeReverse (void)
  898.  
  899. {
  900.     struct SelectionType  *selPtr, *mainSelPtr;
  901.     FlintType             weight, weight2;
  902.     Bool                  successful;
  903.  
  904.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  905.  
  906.     for (mainSelPtr = ui_sel_listPtr;
  907.      (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  908.      mainSelPtr = mainSelPtr->nextPtr) { 
  909.     /* main loop */
  910.  
  911.     for (selPtr = ui_sel_listPtr;
  912.          (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  913.          selPtr = selPtr->nextPtr) { 
  914.         /* inner loop */
  915.  
  916.         if (mainSelPtr == selPtr) continue;
  917.  
  918.         if (ui_utilIsNotSet(selPtr->flags, UI_ALREADY_REVERSED)) {
  919.         /* CASE 1: */
  920.         /* incoming links */
  921.         /* the other selected unit is not marked */
  922.         
  923.         if ((krui_getUnitInputType(mainSelPtr->unitNo) == SITES) AND
  924.             (krui_getUnitInputType(selPtr->unitNo) != SITES)) {
  925.  
  926.             (void) krui_setCurrentUnit(mainSelPtr->unitNo);
  927.             for (successful = krui_setFirstSite(); successful;
  928.              successful = krui_setNextSite()) {
  929.             
  930.             if (krui_isConnected(selPtr->unitNo)) {
  931.                 char siteName[MAX_NAME_LENGTH];
  932.                 strcpy(siteName, krui_getSiteName());
  933.                 weight = krui_getLinkWeight();
  934.                 
  935.                 (void) krui_setCurrentUnit(selPtr->unitNo);
  936.                 if (krui_setSite(siteName) == UI_SET_OK) {
  937.                 /* such a site exists */
  938.                 if (krui_isConnected(mainSelPtr->unitNo)) {
  939.                     /* bidirectional link: exchange weights */
  940.                     weight2 = krui_getLinkWeight();
  941.                     krui_setLinkWeight(weight);
  942.                     ui_krui_setCurrentLink(selPtr->unitNo, mainSelPtr->unitNo,
  943.                                siteName);
  944.                     krui_setLinkWeight(weight2);
  945.                     
  946.                     /* There are no changes in the graphic, 
  947.                        because the weights are still occuring at
  948.                        the same positions !!! */
  949.                     
  950.                 } else {
  951.                     /* unidirectional link: reverse */
  952.                     ui_action_deleteLink(selPtr->unitNo, 
  953.                              mainSelPtr->unitNo,
  954.                              siteName);
  955.                     ui_action_createLink(mainSelPtr->unitNo, 
  956.                              selPtr->unitNo,
  957.                              siteName, weight);
  958.                 }
  959.                 }
  960.             }
  961.             }
  962.         } else {
  963.             if ((krui_getUnitInputType(mainSelPtr->unitNo) != SITES) AND
  964.             (krui_getUnitInputType(selPtr->unitNo) != SITES)) {
  965.             /* no sites */
  966.             (void) krui_setCurrentUnit(mainSelPtr->unitNo);
  967.             if (krui_isConnected(selPtr->unitNo)) {
  968.                 weight = krui_getLinkWeight();
  969.                 (void) krui_setCurrentUnit(selPtr->unitNo);
  970.                 if (krui_isConnected(mainSelPtr->unitNo)) {
  971.                 /* bidirectional link: exchange weights */
  972.                 weight2 = krui_getLinkWeight();
  973.                 krui_setLinkWeight(weight);
  974.                 ui_krui_setCurrentLink(selPtr->unitNo, 
  975.                                mainSelPtr->unitNo,
  976.                                "");
  977.                 krui_setLinkWeight(weight2);
  978.                 
  979.                 /* There are no changes in the graphic, 
  980.                    because the weights are still occuring at
  981.                    the same positions !!! */
  982.                 
  983.                 } else {
  984.                 /* unidirectional link: reverse */
  985.                 ui_action_deleteLink(selPtr->unitNo, mainSelPtr->unitNo,
  986.                              "");
  987.                 ui_action_createLink(mainSelPtr->unitNo, selPtr->unitNo,
  988.                              "", weight);
  989.                 }
  990.             }
  991.             }
  992.             
  993.         }
  994.         
  995.         /* outgoing links */
  996.  
  997.         if ((krui_getUnitInputType(selPtr->unitNo) == SITES) AND
  998.             (krui_getUnitInputType(mainSelPtr->unitNo) == SITES)) {
  999.             
  1000.             (void) krui_setCurrentUnit(selPtr->unitNo);
  1001.             for (successful = krui_setFirstSite(); successful;
  1002.              successful = krui_setNextSite()) {
  1003.             
  1004.             if (krui_isConnected(mainSelPtr->unitNo)) {
  1005.                 char siteName[MAX_NAME_LENGTH];
  1006.                 strcpy(siteName, krui_getSiteName());
  1007.                 weight = krui_getLinkWeight();
  1008.             
  1009.                 (void) krui_setCurrentUnit(mainSelPtr->unitNo);
  1010.                 if (krui_setSite(siteName) == UI_SET_OK) {
  1011.                 /* such a site exists */
  1012.                 if (krui_isConnected(selPtr->unitNo)) {
  1013.                     /* bidirectional link: exchange weights */
  1014.                     weight2 = krui_getLinkWeight();
  1015.                     krui_setLinkWeight(weight);
  1016.                     ui_krui_setCurrentLink(mainSelPtr->unitNo, 
  1017.                                selPtr->unitNo,
  1018.                                siteName);
  1019.                     krui_setLinkWeight(weight2);
  1020.                     
  1021.                     /* There are no changes in the graphic, 
  1022.                        because the weights are still occuring at
  1023.                        the same positions !!! */
  1024.                     
  1025.                 } else {
  1026.                     /* unidirectional link: reverse */
  1027.                     ui_action_deleteLink(mainSelPtr->unitNo, 
  1028.                              selPtr->unitNo,
  1029.                              siteName);
  1030.                     ui_action_createLink(selPtr->unitNo, 
  1031.                              mainSelPtr->unitNo,
  1032.                              siteName, weight);
  1033.                 }
  1034.                 }
  1035.             }
  1036.             }
  1037.         } else             
  1038.             if ((krui_getUnitInputType(selPtr->unitNo) != SITES) AND
  1039.             (krui_getUnitInputType(mainSelPtr->unitNo) != SITES)) {
  1040.             
  1041.             /* no sites */
  1042.             (void) krui_setCurrentUnit(selPtr->unitNo);
  1043.             if (krui_isConnected(mainSelPtr->unitNo)) {
  1044.                 weight = krui_getLinkWeight();
  1045.                 (void) krui_setCurrentUnit(mainSelPtr->unitNo);
  1046.                 if (krui_isConnected(selPtr->unitNo)) {
  1047.                 /* bidirectional link: exchange weights */
  1048.                 weight2 = krui_getLinkWeight();
  1049.                 krui_setLinkWeight(weight);
  1050.                 ui_krui_setCurrentLink(mainSelPtr->unitNo, 
  1051.                                selPtr->unitNo,
  1052.                                "");
  1053.                 krui_setLinkWeight(weight2);
  1054.                 
  1055.                 /* There are no changes in the graphic, 
  1056.                    because the weights are still occuring at
  1057.                    the same positions !!! */
  1058.                 
  1059.                 } else {
  1060.                 /* unidirectional link: reverse */
  1061.                 ui_action_createLink(selPtr->unitNo, mainSelPtr->unitNo,
  1062.                              "", weight);
  1063.                 ui_action_deleteLink(mainSelPtr->unitNo, selPtr->unitNo,
  1064.                              "");
  1065.                 }
  1066.             }
  1067.             }
  1068.         }
  1069.     }
  1070.     /* now mark the unit */
  1071.     ui_utilSetFlag(mainSelPtr->flags, UI_ALREADY_REVERSED);
  1072.     }
  1073.     
  1074.     /* the operation is done */
  1075.     /* reset all Flags UI_ALREADY_REVERSED */
  1076.     selPtr = ui_sel_listPtr;
  1077.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1078.     ui_utilResetFlag(selPtr->flags, UI_ALREADY_REVERSED);
  1079.     selPtr = selPtr->nextPtr;
  1080.     }
  1081.     ui_info_makeUnitInfoPanelConsistent(); 
  1082.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show markers */
  1083. }
  1084.  
  1085.  
  1086. /*****************************************************************************
  1087.   FUNCTION : ui_action_linksCopy
  1088.  
  1089.   PURPOSE  : copy all/input/output Links of all selected units 
  1090.              to specified unit.
  1091.   RETURNS  : alteration of the network
  1092.   NOTES    :
  1093.  
  1094.   UPDATE   :
  1095. *****************************************************************************/
  1096.  
  1097. void ui_action_linksCopy (void)
  1098.  
  1099. {
  1100.     FlintType weight;  /* source link weight */
  1101.  
  1102.      /* Ptrs to step through the selection list */
  1103.  
  1104.     struct SelectionType  *selPtr;
  1105.     Bool                  successful;
  1106.     int                   unitNo, succNo, predNo;
  1107.  
  1108.     /* *******************  START ********************************* */
  1109.     
  1110.     if ((unitNo = ui_key_unitNo) <= 0) {
  1111.     ui_confirmOk("EDIT: no destination to copy links !");
  1112.     return;
  1113.     }
  1114.  
  1115.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  1116.     
  1117.     for (selPtr = ui_sel_listPtr;
  1118.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  1119.      selPtr = selPtr->nextPtr) {
  1120.     
  1121.     if (ui_utilIsSet(ui_key_linksToHandle, UI_OUT)) {
  1122.         for (succNo = krui_getFirstSuccUnit(selPtr->unitNo, &weight);
  1123.          succNo > 0;
  1124.          succNo = krui_getNextSuccUnit(&weight)) {
  1125.         if (krui_getUnitInputType(succNo) == SITES)
  1126.             ui_action_createLink(unitNo, succNo,
  1127.                      krui_getSiteName(), weight);
  1128.         else
  1129.             ui_action_createLink(unitNo, succNo, "", weight);
  1130.         }
  1131.     } /* end if: UI_OUT set */
  1132.     
  1133.     if (ui_utilIsSet(ui_key_linksToHandle, UI_INPUT) AND
  1134.         (krui_getUnitInputType(selPtr->unitNo) ==
  1135.          krui_getUnitInputType(unitNo))) {
  1136.         
  1137.         (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  1138.         
  1139.         if (krui_getUnitInputType(selPtr->unitNo) == SITES) {
  1140.         for (successful = krui_setFirstSite();
  1141.              successful; successful = krui_setNextSite()) {
  1142.             for(predNo = krui_getFirstPredUnit(&weight);
  1143.             predNo > 0;
  1144.             predNo = krui_getNextPredUnit(&weight)) 
  1145.             ui_action_createLink(predNo, unitNo, 
  1146.                          krui_getSiteName(), weight);
  1147.         }
  1148.         } else { /* direct links */
  1149.         for(predNo = krui_getFirstPredUnit(&weight);
  1150.             predNo > 0;
  1151.             predNo = krui_getNextPredUnit(&weight)) 
  1152.             ui_action_createLink(predNo, unitNo, "", weight);
  1153.         }
  1154.     }
  1155.     }/* end for: selected units exist */
  1156.     ui_info_makeUnitInfoPanelConsistent();
  1157.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  1158. }
  1159.      
  1160.  
  1161. /*****************************************************************************
  1162.   FUNCTION : ui_action_linksCopyEnvironment
  1163.  
  1164.   PURPOSE  : copy all/input/output Links of all selected units 
  1165.              to specified unit.
  1166.   RETURNS  : alteration of the network
  1167.   NOTES    :
  1168.  
  1169.   UPDATE   :
  1170. *****************************************************************************/
  1171.  
  1172. void ui_action_linksCopyEnvironment (void)
  1173.  
  1174. {
  1175.     FlintType weight;  /* source link weight */
  1176.  
  1177.      /* Ptrs to step through the selection list */
  1178.  
  1179.     struct SelectionType  *selPtr;
  1180.     Bool                  successful;
  1181.     int                   unitNo, succNo, copySuccNo, predNo, copyPredNo;
  1182.     struct PosType        succPos, predPos, copySuccPos, copyPredPos;
  1183.  
  1184.     /* *******************  START ********************************* */
  1185.  
  1186.     if (ui_targetUnit.no < 1) {
  1187.     ui_confirmOk("EDIT: invalid TARGET unit! Can't copy links.");
  1188.     return;
  1189.     }
  1190.  
  1191.     if ((unitNo = ui_key_unitNo) < 1) {
  1192.     ui_confirmOk("EDIT: no destination to copy links!");
  1193.     return;
  1194.     }
  1195.  
  1196.     /* there is a unit:
  1197.        - step through all selected units and copy their Links 
  1198.        - take notice from the flags in ui_key_linksToHandle   
  1199.        */
  1200.     
  1201.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  1202.     
  1203.     /* check successors of ui_targetUnit */
  1204.     for (succNo = krui_getFirstSuccUnit(ui_targetUnit.no, &weight);
  1205.      succNo > 0;
  1206.      (void) krui_setCurrentUnit(ui_targetUnit.no), 
  1207.      succNo = krui_getNextSuccUnit(&weight)) {
  1208.     
  1209.     /* get position and calculate the relative position to
  1210.        ui_targetUnit and add the position of unit unitNo */
  1211.     krui_getUnitPosition(succNo, &succPos);
  1212.     /* check whether this unit is selected */
  1213.     selPtr = ui_sel_lookForItem(succNo);
  1214.     if ((selPtr != NULL) AND ui_utilIsSet(selPtr->flags, UI_SELECTED)) {
  1215.         copySuccPos.x = 
  1216.         succPos.x - ui_targetUnit.gridPos.x + ui_key_eventPos.x;
  1217.         copySuccPos.y = 
  1218.         succPos.y - ui_targetUnit.gridPos.y + ui_key_eventPos.y;
  1219.         /* check whether there exists a unit relative to unit unitNo */
  1220.         if ((copySuccNo = 
  1221.          krui_getUnitNoAtPosition(©SuccPos,
  1222.                       selPtr->subNetNo)) > 0) 
  1223.         /* there is a candidate ! */
  1224.         ui_action_createLink(unitNo, copySuccNo, 
  1225.                      ui_link.siteName, weight);
  1226.     }
  1227.     }
  1228.     
  1229.     /* check predecessors of ui_targetUnit */
  1230.     (void) krui_setCurrentUnit(ui_targetUnit.no); /* target */
  1231.  
  1232.     if (krui_getUnitInputType(selPtr->unitNo) == SITES) {
  1233.  
  1234.     for (successful = krui_setFirstSite();
  1235.          successful; successful = krui_setNextSite()) {
  1236.  
  1237.         for (predNo = krui_getFirstPredUnit(&weight);
  1238.          predNo > 0;
  1239.          predNo = krui_getNextPredUnit(&weight)) {
  1240.         /* get position and calculate the relative position to
  1241.            ui_targetUnit and add the position of unit unitNo */
  1242.         krui_getUnitPosition(predNo, &predPos);
  1243.         /* check whether this unit is selected */
  1244.         selPtr = ui_sel_lookForItem(predNo);
  1245.         if ((selPtr != NULL) AND ui_utilIsSet(selPtr->flags, UI_SELECTED)) {
  1246.             copyPredPos.x = 
  1247.             predPos.x - ui_targetUnit.gridPos.x + ui_key_eventPos.x;
  1248.             copyPredPos.y = 
  1249.             predPos.y - ui_targetUnit.gridPos.y + ui_key_eventPos.y;
  1250.             /* check whether there exists a unit relative to unit unitNo */
  1251.             if ((copyPredNo = 
  1252.              krui_getUnitNoAtPosition(©PredPos,
  1253.                           selPtr->subNetNo)) > 0) {
  1254.             /* there is a candidate ! */
  1255.             ui_action_createLink(copyPredNo, unitNo, 
  1256.                          krui_getSiteName(), weight);
  1257.             }
  1258.         }
  1259.         }
  1260.     }
  1261.     } else {
  1262.     /* direct links */
  1263.     for (predNo = krui_getFirstPredUnit(&weight);
  1264.          predNo > 0;
  1265.          predNo = krui_getNextPredUnit(&weight)) {
  1266.         /* get position and calculate the relative position to
  1267.            ui_targetUnit and add the position of unit unitNo */
  1268.         krui_getUnitPosition(predNo, &predPos);
  1269.         /* check whether this unit is selected */
  1270.         selPtr = ui_sel_lookForItem(predNo);
  1271.         if ((selPtr != NULL) AND ui_utilIsSet(selPtr->flags, UI_SELECTED)) {
  1272.         copyPredPos.x = 
  1273.             predPos.x - ui_targetUnit.gridPos.x + ui_key_eventPos.x;
  1274.         copyPredPos.y = 
  1275.             predPos.y - ui_targetUnit.gridPos.y + ui_key_eventPos.y;
  1276.         /* check whether there exists a unit relative to unit unitNo */
  1277.         if ((copyPredNo = 
  1278.              krui_getUnitNoAtPosition(©PredPos,
  1279.                           selPtr->subNetNo)) > 0) {
  1280.             /* there is a candidate ! */
  1281.             ui_action_createLink(copyPredNo, unitNo, "", weight);
  1282.         }
  1283.         }
  1284.     }
  1285.     }
  1286.     ui_info_makeUnitInfoPanelConsistent();
  1287.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  1288. }
  1289.  
  1290.  
  1291. /*****************************************************************************
  1292.   FUNCTION : ui_action_sitesCopy
  1293.  
  1294.   PURPOSE  : copy all sites of the target unit shown in the info panel to all
  1295.              selected units. Depending on ui_key_linksToHandle the links will
  1296.          be copied too.
  1297.   RETURNS  : alteration of the network
  1298.   NOTES    :
  1299.  
  1300.   UPDATE   :
  1301. *****************************************************************************/
  1302.  
  1303. void ui_action_sitesCopy (void)
  1304.  
  1305. {
  1306.     FlintType weight;  /* source link weight */
  1307.  
  1308.      /* Ptrs to step through the selection list */
  1309.  
  1310.     struct SelectionType  *selPtr;
  1311.     int                   unitNo, predNo;
  1312.  
  1313.     /* *******************  START ********************************* */
  1314.     
  1315.     if ((unitNo = ui_key_unitNo) <= 0) {
  1316.     ui_confirmOk("EDIT: no destination to copy links !");
  1317.     return;
  1318.     }
  1319.  
  1320.     if (krui_getUnitInputType(ui_targetUnit.no) != SITES) {
  1321.     ui_confirmOk("EDIT: TARGET doesn't have sites!");
  1322.     return;
  1323.     }
  1324.  
  1325.     (void) krui_setCurrentUnit(ui_targetUnit.no); /* target */
  1326.     if ((ui_link.siteName == NULL) OR 
  1327.     (strlen(ui_link.siteName) == 0) OR
  1328.     (krui_setSite(ui_link.siteName) != UI_SET_OK)) {
  1329.     ui_confirmOk("EDIT: Invalid site of TARGET!");
  1330.     return;
  1331.     }
  1332.     
  1333.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  1334.     
  1335.     for (selPtr = ui_sel_listPtr;
  1336.      (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  1337.      selPtr = selPtr->nextPtr) { 
  1338.  
  1339.     if (krui_getUnitInputType(selPtr->unitNo) == DIRECT_LINKS) 
  1340.         continue;
  1341.         
  1342.     (void) krui_setCurrentUnit(selPtr->unitNo); /* target */
  1343.     
  1344.     if (krui_setSite(ui_link.siteName) != UI_SET_OK) 
  1345.         /* site doesn't exist */
  1346.         ui_checkError(krui_addSite(ui_link.siteName));
  1347.     
  1348.     if ((ui_kernelError == 0) AND
  1349.         ui_utilIsSet(ui_key_linksToHandle, UI_INPUT)) {
  1350.         for(predNo = krui_getFirstPredUnit(&weight);
  1351.         predNo > 0;
  1352.         predNo = krui_getNextPredUnit(&weight)) 
  1353.         ui_action_createLink(predNo, unitNo, 
  1354.                      ui_link.siteName, weight);
  1355.     }
  1356.     
  1357.     }/* end for: selected units exist */
  1358.     ui_info_makeUnitInfoPanelConsistent();
  1359.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  1360. }
  1361.  
  1362.  
  1363. /*****************************************************************************
  1364.   FUNCTION : ui_action_sitesMake
  1365.  
  1366.   PURPOSE  : Depending on op a site will be added to (UI_DRAW) or deleted 
  1367.              (UI_ERASE) from all selected unit.
  1368.   RETURNS  : alteration of the network
  1369.   NOTES    :
  1370.  
  1371.   UPDATE   :
  1372. *****************************************************************************/
  1373.  
  1374. void ui_action_sitesMake (int op)
  1375.  
  1376. {
  1377.     struct SelectionType  *mainSelPtr;
  1378.     char  buf[MAX_NAME_LENGTH];
  1379.     Bool  directLinks = FALSE;
  1380.  
  1381.     if (NOT ui_krui_sitesExistInNetwork()) return;
  1382.     
  1383.     if (NOT ui_action_getSite(UI_GENERAL)) return;
  1384.  
  1385.     for (mainSelPtr = ui_sel_listPtr;
  1386.      (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  1387.      mainSelPtr = mainSelPtr->nextPtr) { 
  1388.  
  1389.     (void) krui_setCurrentUnit(mainSelPtr->unitNo);
  1390.     switch (krui_getUnitInputType(mainSelPtr->unitNo)) {
  1391.       case SITES:
  1392.         if (op == UI_DRAW) {
  1393.         if (krui_setSite(ui_action_siteName) != UI_SET_OK) 
  1394.             /* site doesn't exist */
  1395.             ui_checkError(krui_addSite(ui_action_siteName));
  1396.         } else {
  1397.         if (krui_setSite(ui_action_siteName) == UI_SET_OK) { 
  1398.             /* site exists */
  1399.             ui_checkError(krui_setSiteName(ui_action_siteName));
  1400.             ui_checkError(krui_deleteSite());
  1401.         }
  1402.         }
  1403.         break;
  1404.       case DIRECT_LINKS:
  1405.         if (op == UI_DRAW) {
  1406.         directLinks = TRUE;
  1407.         sprintf(buf,"EDIT (sites add): unit %d has direct links!",
  1408.             mainSelPtr->unitNo);
  1409.         ui_tw_printMessage(buf);
  1410.         }
  1411.         break;
  1412.       case NO_INPUTS:
  1413.         if (op == UI_DRAW)
  1414.         ui_checkError(krui_addSite(ui_action_siteName));
  1415.         break;
  1416.     }
  1417.     }
  1418.  
  1419.     if ((op == UI_DRAW) AND directLinks) 
  1420.     ui_confirmOk("Couldn't add site to some units!");
  1421. }
  1422.  
  1423.  
  1424. /*****************************************************************************
  1425.   FUNCTION : ui_action_linksMakeClique
  1426.  
  1427.   PURPOSE  : Insert Links beetween all selected units, that they form a
  1428.              clique, i.e. every unit is connected to all other units.
  1429.   RETURNS  : alteration of the network
  1430.   NOTES    :
  1431.  
  1432.   UPDATE   :
  1433. *****************************************************************************/
  1434.  
  1435. void ui_action_linksMakeClique (int op)
  1436.  
  1437. {
  1438.     struct SelectionType    *selPtr, *mainSelPtr;
  1439.     FlintType               weight;
  1440.  
  1441.     (void) ui_action_getSite(UI_GENERAL);
  1442.  
  1443.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  1444.  
  1445.     weight = (FlintType) ui_xFloatFromAsciiWidget(ui_linkWidgets.weight);
  1446.  
  1447.     for (mainSelPtr = ui_sel_listPtr;
  1448.      (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  1449.      mainSelPtr = mainSelPtr->nextPtr) { 
  1450.     /* main loop */
  1451.  
  1452.     for (selPtr = ui_sel_listPtr;
  1453.          (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  1454.          selPtr = selPtr->nextPtr) { 
  1455.         /* inner loop */
  1456.         if (NOT (selPtr == mainSelPtr)) { /* not the same entry !! */
  1457.         
  1458.         if (op == UI_DRAW) {
  1459.             ui_action_createLink(selPtr->unitNo, mainSelPtr->unitNo,
  1460.                      ui_action_siteName, weight);
  1461.             ui_action_createLink(mainSelPtr->unitNo, selPtr->unitNo,
  1462.                      ui_action_siteName, weight);
  1463.         } else {
  1464.             ui_action_deleteLink(selPtr->unitNo, mainSelPtr->unitNo,
  1465.                      ui_action_siteName);
  1466.             ui_action_deleteLink(mainSelPtr->unitNo, selPtr->unitNo,
  1467.                      ui_action_siteName);
  1468.         }
  1469.         }
  1470.     }
  1471.     }
  1472.     ui_info_makeUnitInfoPanelConsistent(); 
  1473.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show markers */
  1474. }
  1475.  
  1476.  
  1477. /*****************************************************************************
  1478.   FUNCTION : ui_action_linksSet
  1479.  
  1480.   PURPOSE  : Set the weight of all links beetween the selected unit. The 
  1481.              value will be taken from the unit-info-panel.
  1482.   RETURNS  : alteration of the network
  1483.   NOTES    :
  1484.  
  1485.   UPDATE   :
  1486. *****************************************************************************/
  1487.  
  1488. void ui_action_linksSet (void)
  1489.  
  1490. {
  1491.     struct SelectionType   *selPtr, *mainSelPtr;
  1492.     FlintType              weight, newWeight;
  1493.     Bool       siteChoosed = ui_action_getSite(UI_GENERAL);
  1494.     Bool       performSet  = FALSE;
  1495.  
  1496.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* delete markers */
  1497.     newWeight = (FlintType) ui_xFloatFromAsciiWidget(ui_linkWidgets.weight);
  1498.  
  1499.     for (mainSelPtr = ui_sel_listPtr;
  1500.      (mainSelPtr = ui_sel_lookForSelectedItem(mainSelPtr)) != NULL;
  1501.      mainSelPtr = mainSelPtr->nextPtr) { 
  1502.     /* main loop */
  1503.  
  1504.     for (selPtr = ui_sel_listPtr;
  1505.          (selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL;
  1506.          selPtr = selPtr->nextPtr) { 
  1507.         /* inner loop */
  1508.         
  1509.         (void) krui_setCurrentUnit(mainSelPtr->unitNo); /* target */
  1510.         if (siteChoosed AND (krui_getUnitInputType(mainSelPtr->unitNo) == SITES)) {
  1511.         if (krui_setSite(ui_action_siteName) == UI_SET_OK) 
  1512.             performSet = krui_isConnected(selPtr->unitNo);
  1513.  
  1514.         } else
  1515.         performSet =
  1516.             ((NOT siteChoosed) AND 
  1517.              (krui_getUnitInputType(mainSelPtr->unitNo) != SITES)AND
  1518.              (krui_isConnected(selPtr->unitNo)));
  1519.  
  1520.         if (performSet) {
  1521.         weight = krui_getLinkWeight();
  1522.         krui_setLinkWeight(newWeight);
  1523.         ui_net_drawLink(ui_currentDisplay, UI_GLOBAL,
  1524.                 selPtr->unitNo, mainSelPtr->unitNo, 
  1525.                 weight, UI_ERASE);
  1526.         ui_net_drawLink(ui_currentDisplay, UI_GLOBAL,
  1527.                 selPtr->unitNo, mainSelPtr->unitNo, 
  1528.                 newWeight, UI_DRAW);
  1529.         }            
  1530.     } /* end inner loop */
  1531.     } /* end outer loop */
  1532.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL);
  1533. }
  1534.  
  1535.  
  1536. /*****************************************************************************
  1537.   FUNCTION : ui_action_unitsDelete
  1538.  
  1539.   PURPOSE  : Delete all selected units.
  1540.   RETURNS  : alteration of the network
  1541.   NOTES    : The graphic update is made in dependency of the number of units
  1542.              in the network and the number of selected units. If there are
  1543.          many units to delete, the whole graphic is built completly new.
  1544.          If there are only a few units to delete, GUI delete all links
  1545.          from and to the selected units and at last the units itsselves.
  1546.          This way is much faster when dealing with big networks and
  1547.          deleting only a few units.
  1548.  
  1549.   UPDATE   :
  1550. *****************************************************************************/
  1551.  
  1552. void ui_action_unitsDelete (void)
  1553.  
  1554. {
  1555.     struct SelectionType  *selPtr, *tempPtr;
  1556.     struct PosType        unitPos;
  1557.     Bool                  deleteFewUnits, zExists, clearEntry;
  1558.     int                   act_unit;
  1559.     d3_unitPtrType        *unitList, *unitPtr;
  1560.     int                   i;
  1561.     int                   no_of_sel_units;
  1562.     int                   *unit_delete_list;
  1563.     int  x, y;
  1564.    
  1565.     if (krui_getNoOfUnits() > 0) {
  1566.  
  1567.         /* clear all entries in the translation table if a z-value don't
  1568.            exist */
  1569.  
  1570.         /* store all z-values in a list */
  1571.  
  1572.         selPtr = ui_sel_listPtr;
  1573.         
  1574.         unitList = NULL;
  1575.         while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1576.            krui_getUnitPosition (selPtr->unitNo, &unitPos);
  1577.            unitPtr = unitList;
  1578.            zExists = FALSE;
  1579.            while (unitPtr != NULL) {
  1580.                if (unitPtr->unitNo == unitPos.z) {
  1581.                   zExists = TRUE;
  1582.                   break;
  1583.                }
  1584.                unitPtr = unitPtr->next;
  1585.            }
  1586.            if (! zExists)
  1587.                d3_insertUnit (&unitList, unitPos.z);           
  1588.            selPtr  = selPtr->nextPtr;
  1589.         }
  1590.  
  1591.         deleteFewUnits = 
  1592.             ((3 * ui_sel_numberOfSelectedItems) < krui_getNoOfUnits());
  1593.         
  1594.         selPtr = ui_sel_listPtr;
  1595.         no_of_sel_units = ui_sel_numberOfSelectedItems;
  1596.  
  1597.         /* Allocate memory for the list of units to be deleted */
  1598.         if ((unit_delete_list = calloc(no_of_sel_units, sizeof(int)))==NULL) 
  1599.         {
  1600.           ui_confirmOk("Error! Can't allocate Memory\n");
  1601.           return;
  1602.         } /*if*/
  1603.         
  1604.         i = 0;
  1605.         while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1606.             tempPtr = selPtr;
  1607.             selPtr  = selPtr->nextPtr;
  1608.             ui_sel_unselectOne(ui_currentDisplay, UI_GLOBAL, 
  1609.                                tempPtr->unitNo, tempPtr->gridPos); 
  1610.             /* kill the selection */
  1611.             /* this will take item tempPtr out of the list. Therefore this
  1612.                construction !! */
  1613.             if (deleteFewUnits) {
  1614.                 /* erase all links from/to this unit in the graphic */
  1615.                 ui_net_drawAllLinksToUnit(ui_currentDisplay, UI_GLOBAL, 
  1616.                                           tempPtr->unitNo, UI_ERASE);
  1617.                 ui_net_drawAllLinksFromUnit(ui_currentDisplay, UI_GLOBAL, 
  1618.                                             tempPtr->unitNo, UI_ERASE);
  1619.                 /* erase the unit in the graphic */
  1620.                 ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  1621.                                 tempPtr->unitNo, UI_ERASE);
  1622.             }
  1623.  
  1624.             unit_delete_list[i] = tempPtr->unitNo;
  1625.             i++;
  1626.             
  1627.         }
  1628.  
  1629.         ui_checkError(krui_deleteUnitList(no_of_sel_units, unit_delete_list));
  1630.  
  1631.         if (NOT deleteFewUnits)
  1632.             ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL);
  1633.         
  1634.         /* make sure the unit info panel is consistent after deleting units */
  1635.         ui_info_makeUnitInfoPanelConsistent();
  1636.         ui_sel_msgNumber();
  1637.  
  1638.         /* if all units in a z-layer are deleted then clear table entry*/
  1639.  
  1640.         unitPtr = unitList;
  1641.         while (unitPtr != NULL) {
  1642.             clearEntry = TRUE;
  1643.             act_unit = krui_getFirstUnit ();
  1644.             while (act_unit != 0)  {
  1645.                 krui_getUnitPosition (act_unit, &unitPos);
  1646.                 if (unitPos.z == unitPtr->unitNo) {
  1647.                     clearEntry = FALSE;
  1648.                     break;
  1649.                 }
  1650.                 act_unit = krui_getNextUnit ();
  1651.             }
  1652.  
  1653.             if (clearEntry) {
  1654.                 x=y=0;
  1655.                 krui_xyTransTable( OP_TRANSTABLE_SET, &x, &y, unitPtr->unitNo );
  1656.             }    
  1657.             unitPtr = unitPtr->next;
  1658.         }
  1659.         d3_drawNet ();
  1660.     }
  1661.  
  1662.     free(unit_delete_list);
  1663. }
  1664.  
  1665.  
  1666. /*****************************************************************************
  1667.   FUNCTION : ui_action_setUnitLayers
  1668.  
  1669.   PURPOSE  : displays the layer panel and sets the layer of all selected units
  1670.   RETURNS  : void
  1671.   NOTES    :
  1672.  
  1673.   UPDATE   : 5.9.1990
  1674. ******************************************************************************/
  1675.  
  1676. void ui_action_setUnitLayers (void)
  1677.  
  1678. {
  1679.     Position                   x, y;
  1680.     struct SelectionType      *selPtr;
  1681.  
  1682.     if ((selPtr = ui_sel_lookForSelectedItem(ui_sel_listPtr)) == NULL) 
  1683.     return;
  1684.  
  1685.     /* There are selected units. */
  1686.  
  1687.     XtTranslateCoords(ui_currentDisplay->widget, 
  1688.               (Position) 5, (Position) 5, &x, &y);
  1689.     /* set start value of the buttons */
  1690.     ui_layerStartValue = krui_getUnitLayerNo(selPtr->unitNo);
  1691.  
  1692.     ui_displayLayerPanel(x,y); /* absolute screen coordinates */
  1693.  
  1694.  
  1695.     selPtr = ui_sel_listPtr;
  1696.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1697.     /* assign return value */
  1698.     krui_setUnitLayerNo(selPtr->unitNo, (int) ui_layerReturnValue);
  1699.     selPtr = selPtr->nextPtr;
  1700.     }
  1701.     ui_sel_checkList(ui_currentDisplay, UI_GLOBAL);
  1702.     ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL);
  1703. }
  1704.  
  1705.  
  1706.  
  1707. /*****************************************************************************
  1708.   FUNCTION : ui_action_setUnitAttribute
  1709.  
  1710.   PURPOSE  : set one attribute of all selected units to the correspondent 
  1711.              value of the SOURCE displayed in the unit-info-panel
  1712.   RETURNS  : alteration of the network
  1713.   NOTES    : The argument determines the attribute. The following predefined
  1714.              constants exist (defined in ui.h):
  1715.          UI_SET_NAME          1
  1716.          UI_SET_TYPE          2
  1717.          UI_SET_ACT           3
  1718.          UI_SET_BIAS          4
  1719.          UI_SET_ACT_FUNC      5
  1720.  
  1721.   UPDATE   :
  1722. *****************************************************************************/
  1723.  
  1724. void ui_action_setUnitAttribute (FlagType whatToSet)
  1725.  
  1726. {
  1727.     static struct SimpleListType     listStruct;
  1728.     static struct UnitAttributeType  unit;
  1729.  
  1730.     struct SelectionType    *selPtr;
  1731.     Position                x, y; /* for list panels */
  1732.     int                     err,olderr;
  1733.  
  1734.     unit = ui_targetUnit;
  1735.     ui_info_getDisplayedUnitAttributes(&ui_targetWidgets, &unit);
  1736.     listStruct.unitPtr  = &unit;
  1737.     listStruct.widgetPtr= NULL;
  1738.     XtTranslateCoords(ui_currentDisplay->widget, 
  1739.               (Position) 5, (Position) 5, &x, &y);    
  1740.     switch (whatToSet) {
  1741.       case UI_SET_IOTYPE:
  1742.     sprintf(listStruct.msg,"Set io-type of selected units");
  1743.     listStruct.listType = UI_LIST_IOTYPE;
  1744.     ui_listPopup((struct SimpleListType *) &listStruct, x,y);
  1745.     break;
  1746.       case UI_SET_FTYPE:
  1747.     sprintf(listStruct.msg,"Set f-type of selected units");
  1748.     listStruct.listType = UI_LIST_FTYPE;
  1749.     ui_listPopup((struct SimpleListType *) &listStruct, x,y);
  1750.     break;
  1751.       case UI_SET_ACT_FUNC:
  1752.     sprintf(listStruct.msg,"Set activation-function of selected units");
  1753.     listStruct.listType = UI_LIST_ACT_FUNC;
  1754.     ui_listPopup((struct SimpleListType *) &listStruct, x,y);
  1755.     break;
  1756.       case UI_SET_OUT_FUNC:
  1757.     sprintf(listStruct.msg,"Set output-function of selected units");
  1758.     listStruct.listType = UI_LIST_OUT_FUNC;
  1759.     ui_listPopup((struct SimpleListType *) &listStruct, x,y);
  1760.     break;
  1761.     }
  1762.  
  1763.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* erase all selection markers */
  1764.  
  1765.     if ((whatToSet == UI_SET_ACT) OR
  1766.     (whatToSet == UI_SET_OUT)) {
  1767.     /* reset counter in the remote panel */
  1768.     ui_rem_resetCounter();
  1769.     }
  1770.  
  1771.     olderr = KRERR_NO_ERROR;
  1772.     err = KRERR_NO_ERROR;
  1773.     selPtr = ui_sel_listPtr;
  1774.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1775.     
  1776.     ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  1777.             selPtr->unitNo, UI_ERASE);
  1778.  
  1779.     switch (whatToSet) {
  1780.       case UI_SET_NAME:
  1781.         err = krui_setUnitName(selPtr->unitNo, unit.name);
  1782.         if (ui_kernelError == KRERR_SYMBOL) {
  1783.         ui_correctName(unit.name);
  1784.            err = krui_setUnitName(selPtr->unitNo, unit.name);
  1785.         }
  1786.         break;
  1787.       case UI_SET_IOTYPE:
  1788.         err = krui_setUnitTType(selPtr->unitNo, unit.iotype);
  1789.         break;
  1790.       case UI_SET_FTYPE:
  1791.         err = krui_setUnitFType(selPtr->unitNo, unit.ftype);
  1792.         break;
  1793.       case UI_SET_ACT_FUNC:
  1794.         err = krui_setUnitActFunc(selPtr->unitNo, unit.actFuncName);
  1795.         break;
  1796.       case UI_SET_OUT_FUNC:
  1797.         err = krui_setUnitOutFunc(selPtr->unitNo, unit.outFuncName);
  1798.         break;
  1799.       case UI_SET_ACT:
  1800.         err = krui_setUnitActivation(selPtr->unitNo, unit.act);
  1801.         break;
  1802.       case UI_SET_I_ACT:
  1803.         krui_setUnitInitialActivation(selPtr->unitNo, unit.i_act);
  1804.         break;
  1805.       case UI_SET_OUT:
  1806.         err = krui_setUnitOutput(selPtr->unitNo, unit.out);
  1807.         break;
  1808.       case UI_SET_BIAS:
  1809.         krui_setUnitBias(selPtr->unitNo, unit.bias);
  1810.         break;
  1811.       case UI_FREEZE:
  1812.         err = krui_freezeUnit(selPtr->unitNo);
  1813.         break;
  1814.       case UI_UNFREEZE:
  1815.         err = krui_unfreezeUnit(selPtr->unitNo);
  1816.     }
  1817.     ui_net_drawUnit(ui_currentDisplay, UI_GLOBAL,
  1818.             selPtr->unitNo, UI_DRAW);
  1819.     selPtr = selPtr->nextPtr;           /* next list entry        */
  1820.     
  1821.     if(err != olderr){
  1822.         ui_checkError(err);
  1823.         olderr = err;
  1824.     }
  1825.     }
  1826.     ui_info_makeUnitInfoPanelConsistent();
  1827.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show all selected items */
  1828. }
  1829.  
  1830.  
  1831. /*****************************************************************************
  1832.   FUNCTION : ui_action_unitSetDefaultType
  1833.  
  1834.   PURPOSE  : sets the st-attribute of all selected units according to its
  1835.              real topological type i.e. 
  1836.          if the unit has input and no output links -> OUTPUT
  1837.          if the unit has output and no input links -> INPUT
  1838.          if the unit has both kinds of links       -> HIDDEN
  1839.   RETURNS  : alteration of the network
  1840.   NOTES    : 
  1841.  
  1842.   UPDATE   : 26.8.90
  1843. *****************************************************************************/
  1844.  
  1845. void ui_action_unitSetDefaultType (void)
  1846.  
  1847. {
  1848.     struct SelectionType    *selPtr;
  1849.     Bool                    inputExist, outputExist;
  1850.     FlintType               weight;
  1851.     
  1852.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* erase all selection markers */
  1853.  
  1854.     selPtr = ui_sel_listPtr;
  1855.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1856.     inputExist  = (krui_getUnitInputType(selPtr->unitNo) != NO_INPUTS);
  1857.     outputExist = (krui_getFirstSuccUnit(selPtr->unitNo, &weight) > 0);
  1858.  
  1859.     if (inputExist == outputExist)
  1860.         ui_checkError(krui_setUnitTType(selPtr->unitNo, HIDDEN));
  1861.     else {
  1862.         if (inputExist AND NOT outputExist)
  1863.         ui_checkError(krui_setUnitTType(selPtr->unitNo, OUTPUT));
  1864.         else
  1865.         ui_checkError(krui_setUnitTType(selPtr->unitNo, INPUT));
  1866.     }
  1867.     selPtr = selPtr->nextPtr;           /* next list entry        */
  1868.     }
  1869.     ui_info_makeUnitInfoPanelConsistent();
  1870.     ui_sel_reshowItems(ui_currentDisplay, UI_GLOBAL); /* show all selected items */
  1871. }
  1872.  
  1873.  
  1874. /*****************************************************************************
  1875.   FUNCTION : ui_action_graphicsDirection
  1876.  
  1877.   PURPOSE  : Set the weight of all links beetween the selected unit. The 
  1878.              value will be taken from the unit-info-panel.
  1879.   RETURNS  : alteration of the network
  1880.   NOTES    :
  1881.  
  1882.   UPDATE   :
  1883. *****************************************************************************/
  1884.  
  1885. void ui_action_graphicsDirection (void)
  1886.  
  1887. {
  1888.     Bool          showLinkFlg;
  1889.     Bool          showDirectionFlg;
  1890.     FlintType     linkPosTrigger, linkNegTrigger;
  1891.  
  1892.     if (ui_key_unitNo <= 0)
  1893.     return;
  1894.     
  1895.     ui_sel_reshowItems(ui_currentDisplay, UI_LOCAL); /* delete markers */
  1896.  
  1897.     /* save old setup, set new values and draw all links */
  1898.     showLinkFlg      = (ui_currentDisplay->setup).showLinkFlg;
  1899.     showDirectionFlg = (ui_currentDisplay->setup).showDirectionFlg;
  1900.     linkPosTrigger   = (ui_currentDisplay->setup).linkPosTrigger;
  1901.     linkNegTrigger   = (ui_currentDisplay->setup).linkNegTrigger;
  1902.  
  1903.     (ui_currentDisplay->setup).showLinkFlg      = TRUE;
  1904.     (ui_currentDisplay->setup).showDirectionFlg = TRUE;
  1905.     (ui_currentDisplay->setup).linkPosTrigger   = 0.0;
  1906.     (ui_currentDisplay->setup).linkNegTrigger   = 0.0;
  1907.  
  1908.     ui_net_drawAllLinksToUnit  (ui_currentDisplay, UI_LOCAL, 
  1909.                 ui_key_unitNo, UI_DRAW);
  1910.     ui_net_drawAllLinksFromUnit(ui_currentDisplay, UI_LOCAL, 
  1911.                 ui_key_unitNo, UI_DRAW);
  1912.  
  1913.     /* restore old values */
  1914.     (ui_currentDisplay->setup).showLinkFlg      = showLinkFlg;
  1915.     (ui_currentDisplay->setup).showDirectionFlg = showDirectionFlg;
  1916.     (ui_currentDisplay->setup).linkPosTrigger   = linkPosTrigger;
  1917.     (ui_currentDisplay->setup).linkNegTrigger   = linkNegTrigger;
  1918.  
  1919.     ui_sel_reshowItems(ui_currentDisplay, UI_LOCAL);
  1920. }
  1921.  
  1922.  
  1923. /*****************************************************************************
  1924.   FUNCTION : ui_action_graphicsGrid
  1925.  
  1926.   PURPOSE  : displays a single point on every raster position visible in 
  1927.              ui_currentDisplay.
  1928.   RETURNS  : void
  1929.   NOTES    :
  1930.  
  1931.   UPDATE   : 20.9.1990
  1932. ******************************************************************************/
  1933.  
  1934. void ui_action_graphicsGrid (void)
  1935.  
  1936. {
  1937.     struct PosType pos;
  1938.  
  1939.     ui_sel_reshowItems(ui_currentDisplay, UI_LOCAL);
  1940.     
  1941.     for (pos.x = ui_currentDisplay->origin.x; 
  1942.      pos.x <= ui_currentDisplay->unitsInX; pos.x++)
  1943.     for (pos.y = ui_currentDisplay->origin.y; 
  1944.          pos.y <= ui_currentDisplay->unitsInY; pos.y++) {
  1945.         XSetFunction(ui_display, ui_gc, GXcopy);
  1946.         ui_xDrawPoint(ui_display, ui_currentDisplay->drawable, 
  1947.               ui_gc, ui_utilGridToPix(ui_currentDisplay, pos));
  1948.     }
  1949.  
  1950.     ui_sel_reshowItems(ui_currentDisplay, UI_LOCAL);
  1951. }
  1952.  
  1953.  
  1954. /*****************************************************************************
  1955.   FUNCTION : ui_action_UnitZcoordinate
  1956.  
  1957.   PURPOSE  : sets the Z coordinate for the selected units
  1958.   RETURNS  : void
  1959.   NOTES    : 
  1960.  
  1961.   UPDATE   : 28.8.1991
  1962. ******************************************************************************/
  1963.  
  1964. void ui_action_UnitZcoordinate (void)
  1965.  
  1966. {
  1967.     struct PosType          unitPos;
  1968.     struct SelectionType   *selPtr;
  1969.  
  1970.     short                   selected_z;
  1971.     int                     act_unit;
  1972.     Bool                    clearEntry;
  1973.     int  x, y;
  1974.  
  1975.     if ((selPtr = ui_sel_lookForSelectedItem(ui_sel_listPtr)) == NULL) 
  1976.     return;
  1977.  
  1978.     /* There are selected units. */
  1979.  
  1980.     /* Check wether all units have the same z-value */
  1981.  
  1982.     selPtr = ui_sel_listPtr;
  1983.     krui_getUnitPosition (selPtr->unitNo, &unitPos);
  1984.     selected_z = unitPos.z;
  1985.     selPtr = selPtr->nextPtr;
  1986.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1987.         krui_getUnitPosition (selPtr->unitNo, &unitPos);
  1988.         if (unitPos.z != selected_z)  {
  1989.              fprintf (stdout, "D3-ERROR: the selected units dont have the same z-value\n\n");
  1990.              return;
  1991.     }
  1992.     selPtr = selPtr->nextPtr;
  1993.     }
  1994.  
  1995.     /* set selected units to new z */
  1996.  
  1997.     selPtr = ui_sel_listPtr;
  1998.     while ((selPtr = ui_sel_lookForSelectedItem(selPtr)) != NULL) {
  1999.         krui_getUnitPosition (selPtr->unitNo, &unitPos);
  2000.         unitPos.z = ui_actualZvalue;
  2001.         krui_setUnitPosition (selPtr->unitNo, &unitPos);
  2002.  
  2003.     selPtr = selPtr->nextPtr;
  2004.     }
  2005.  
  2006.     /* move translation table entry */
  2007.  
  2008.     krui_xyTransTable( OP_TRANSTABLE_GET, &x, &y, selected_z );
  2009.     krui_xyTransTable( OP_TRANSTABLE_SET, &x, &y, ui_actualZvalue );
  2010.  
  2011.     /* if there are no more units with the old z-value then clear the old
  2012.        translation table entry                                             */
  2013.  
  2014.     clearEntry = TRUE;
  2015.     act_unit = krui_getFirstUnit ();
  2016.     while (act_unit != 0)  {
  2017.         krui_getUnitPosition (act_unit, &unitPos);
  2018.         if (unitPos.z == selected_z) {
  2019.              clearEntry = FALSE;
  2020.              break;
  2021.     }
  2022.         act_unit = krui_getNextUnit ();
  2023.     }
  2024.  
  2025.     if (clearEntry) {
  2026.         x=y=0;
  2027.         krui_xyTransTable( OP_TRANSTABLE_SET, &x, &y, selected_z );
  2028.     }    
  2029.     
  2030.     ui_sel_checkList(ui_currentDisplay, UI_GLOBAL);
  2031.  
  2032.     ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL);
  2033.  
  2034. }
  2035.  
  2036.  
  2037. /*****************************************************************************
  2038.   FUNCTION : ui_action_UnitZsetReference
  2039.  
  2040.   PURPOSE  : sets the the reference flag in the unit structure
  2041.   RETURNS  : void
  2042.   NOTES    : 
  2043.  
  2044.   UPDATE   : 28.8.1991
  2045. ******************************************************************************/
  2046.  
  2047. void ui_action_UnitZsetReference (void)
  2048.  
  2049. {
  2050.     struct PosType             unitPos;
  2051.     struct SelectionType      *selPtr;
  2052.     int  x, y;
  2053.  
  2054.     if ((selPtr = ui_sel_lookForSelectedItem(ui_sel_listPtr)) == NULL) 
  2055.     return;
  2056.  
  2057.     selPtr = ui_sel_listPtr;
  2058.  
  2059.     krui_getUnitPosition (selPtr->unitNo, &unitPos);
  2060.  
  2061.     x=unitPos.x - ui_key_eventPos.x;
  2062.     y=unitPos.y - ui_key_eventPos.y;
  2063.     krui_xyTransTable( OP_TRANSTABLE_SET, &x, &y, ui_actualZvalue );
  2064.  
  2065.     ui_sel_checkList(ui_currentDisplay, UI_GLOBAL);
  2066.  
  2067.     ui_net_completeRefresh(ui_currentDisplay, UI_GLOBAL);
  2068. }
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075. /* end of file */
  2076. /* lines: 2143 */
  2077.